#ifndef _X7_H_INCLUDED_
#define _X7_H_INCLUDED_
#include <string>
using std::string;
const char keywords[] = "data: $";
const int MAX_RECV_SIZE = 1024;
class X7
{
private:
    int status = 0;
public:
    bool is_complete = false; 
    bool protocolParser(const char* buffer,int size)
    {
        if (status < 0){
            return false;
        }       
        for(int i = 0; i < size; i++){
            if(status == 6 && size > 0){
                is_complete = false;
                status = 0;
            }
            if(status != 5){
                if (buffer[i] == keywords[status])
                    status += 1;
                else{
                    status = -1;
                    return false;
                }
            }else{
                if(buffer[i] != '$'){
                    data += buffer[i];
                }
                else{
                    status += 1;
                }
            }
        }
        if(status == 6){
            is_complete = true;
        }
        return true; 
    }
    string data;
    X7() = default;
    void handler();
    static string encoder(string& data);
};

inline string X7::encoder(string& data)
{
    string temp = "data:";
    temp += data + "$";
    return temp;
}

#endif